package com.battle.service.controller.web;

import com.battle.pojo.param.dataLabelingTask.*;
import com.battle.pojo.param.personWarCase.GetPersonWarCaseListParam;
import com.battle.pojo.vo.dataLabelingTask.*;
import com.battle.service.service.in.*;
import jakarta.servlet.http.HttpServletResponse;
import nirvana.core.domains.vo.PageResult;
import nirvana.core.domains.vo.ApiResult;
import nirvana.core.exceptions.BizException;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.Valid;

import java.io.IOException;
import java.util.List;

/**
 * web/数据标注任务
 * 【描 述】：
 * 【环 境】：J2SE
 * 【详 细】：
 */
@RestController
@RequestMapping("/dataLabelingTask/web")
public class DataLabelingTaskWebController {

    private final DataLabelingTaskService service;

    public DataLabelingTaskWebController(DataLabelingTaskService service) {
        this.service = service;
    }


    /**
     * 创建数据标注任务
     *
     * @param param
     * @return
     */
    @PostMapping("/createDataLabelingTask")
    public ApiResult createDataLabelingTask(@RequestBody @Valid CreateDataLabelingTaskParam param) {
        service.createDataLabelingTask(param);
        return ApiResult.ok();
    }


    /**
     * 数据标注
     *
     * @param param
     */
    @PutMapping("/editDataLabelingTask")
    public ApiResult editDataLabelingTask(@RequestBody @Valid EditDataLabelingTaskParam param) {
        service.editDataLabelingTask(param);
        return ApiResult.ok();
    }

    /**
     * 获取数据标注任务详情
     *
     * @param id
     * @return
     */
    @GetMapping("/getDataLabelingTask")
    public ApiResult<GetDataLabelingTaskVo> getDataLabelingTask(@RequestParam("id") Long id) {
        GetDataLabelingTaskVo vo = service.getDataLabelingTask(id);
        return ApiResult.ok(vo);
    }

    /**
     * 获取数据标注任务列表
     *
     * @param param
     * @return
     */
    @PostMapping("/getDataLabelingTaskList")
    public ApiResult<PageResult<GetDataLabelingTaskListVo>> getDataLabelingTaskList(@RequestBody GetDataLabelingTaskListParam param) {
        PageResult<GetDataLabelingTaskListVo> result = service.getDataLabelingTaskList(param);
        return ApiResult.ok(result);
    }

    /**
     * 导出数据标注
     * @param response
     * @param param
     */
    @PostMapping(value = "/exportDataLabelingTaskList")
    public void exportDataLabelingTaskList(HttpServletResponse response, @RequestBody GetDataLabelingTaskListParam param) {
        try {
            service.export(param, response);
        } catch (IOException e) {
            throw new BizException(e.getMessage());
        }
    }


    /**
     * 获得所有的任务数据
     * @return
     */
    @GetMapping("/getDataLabelingGraph")
    public ApiResult<GetDataLabelingGraphVo> getDataLabelingGraph() {
        GetDataLabelingGraphVo vo = service.getDataLabelingGraph();
        return ApiResult.ok(vo);
    }
}

